package com.tvunetworks.center.device.controller;

import com.tvunetworks.center.common.model.LoginUser;
import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.common.util.ResultUtil;
import com.tvunetworks.center.device.annotation.Logined;
import com.tvunetworks.center.device.model.param.CustomizedLiveParam;
import com.tvunetworks.center.device.service.CustomizedLiveService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: tvucc-aggregator
 * @description: CustomizedLiveController
 * @author lebronchen
 * @create: 2020-03-17 15:58
 **/
@RestController
@RequestMapping("/live")
public class CustomizedLiveController {

    @Autowired
    private CustomizedLiveService customizedLiveService;

    /**
     *
     * @param loginUser loginUser
     * @param param param
     * @return success
     */
    @PostMapping("/manualStartLive")
    public Result manualStartLive(@Logined LoginUser loginUser, @RequestBody CustomizedLiveParam param){
        if (loginUser == null) {
            return ResultUtil.noLogin();
        }
        if (StringUtils.isEmpty(param.getSid()) || StringUtils.isEmpty(param.getRid())) {
            return ResultUtil.paramErrorInfo();
        }
        customizedLiveService.manualStartLive(loginUser, param);
        return ResultUtil.success();
    }

    /**
     * 自动开始直播
     * @param loginUser loginUser
     * @param param param
     * @return rid
     */
    @PostMapping("/autoStartLive")
    public Result autoStartLive(@Logined LoginUser loginUser, @RequestBody CustomizedLiveParam param){
        if (loginUser == null) {
            return ResultUtil.noLogin();
        }
        if (StringUtils.isEmpty(param.getSid())) {
            return ResultUtil.paramErrorInfo();
        }
        String rid = customizedLiveService.autoStartLive(loginUser, param);
        return ResultUtil.success(rid);
    }

    /**
     * 停止直播
     * @param loginUser loginUser
     * @param param param
     * @return success
     */
    @PostMapping("/stopLive")
    public Result stopLive(@Logined LoginUser loginUser, @RequestBody CustomizedLiveParam param){
        if (loginUser == null) {
            return ResultUtil.noLogin();
        }
        if (StringUtils.isEmpty(param.getRid())) {
            return ResultUtil.paramErrorInfo();
        }
        customizedLiveService.stopLive(loginUser, param);
        return ResultUtil.success();
    }


}
